/*
 * Program gets date and answers what day of week was this date
 */
import java.util.*;
public class CalendarSeeker{
	public static void main(String[] args){
		// Initialize input form keyboard
		Scanner in = new Scanner(System.in);
		// Initialize names of days and day of initial countdoun(1/1/2007 is Monday)
		final String[] DayNames = new String[] {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
		final int defYear = 2007;
		final int defMonth = 1;
		final int defDay = 1;
		
		// Initialize date that will be input
		int year;
		int month;
		int day;
		System.out.println("Input desired year");
		year = in.nextInt();
		// If month number is higher than 12 then it should be re-input
		do{
			System.out.println("Input desired number of month");
			month = in.nextInt();
			if (month > 12 & month <= 0)
				System.out.println("Invalid month. Try one more time.");
			else break;
		}
		while (month > 0 & month <= 12);
		// If day number is higher than 31 then it should be re-input
		do{
			System.out.println("Input desired day");
			day = in.nextInt();
			if (day > 31 & month <= 0)
				System.out.println("Invalid Day. Try one more time.");
			else break;
		}
		while (day > 0 & day <= 31);
		
		//Initialize difference in days between initial date and input date
		int diff = 0;
		
		// Countdown of difference in days if input date is earlier than initial
		if (year < defYear){
			for (int y = defYear-1; y > year; y--){
				if (y % 4 == 0){
					diff += 366;
					System.out.println("Diff="+diff);
				}
				else{
					diff += 365;
					System.out.println("Diff="+diff);
				}
			}
			for (int m = 12; m > month; m--){
				if (m == 2 & (year % 4 == 0)){
					diff += 29;
					System.out.println("Diff="+diff);
				}
				else if (m == 2 & (year % 4 != 0)){
					diff += 28;
					System.out.println("Diff="+diff);
				}
				else if (m == 4 | m == 6 | m == 9 | m ==11){
					diff += 30;
					System.out.println("Diff="+diff);
				}
				else {
					diff += 31;
					System.out.println("Diff="+diff);
				}
			}
			if (month == 2 & (year % 4 == 0)){
				int d = 30;
				int daydiff = d - day;
				diff += daydiff;
				System.out.println("Diff="+diff);
			}
			else if (month == 2 & (year % 4 != 0)){
				int d = 29;
				int daydiff = d - day;
				diff += daydiff;
				System.out.println("Diff="+diff);
			}
			else if (month == 4 | month == 6 | month == 9 | month ==11){
				int d = 31;
				int daydiff = d - day;
				diff += daydiff;
				System.out.println("Diff="+diff);
			}
			else {
				int d = 32;
				int daydiff = d - day;
				diff += daydiff;
				System.out.println("Diff="+diff);
			}
			// Divide day difference by 7 to get number of full weeks between two dates
			int dayOfWeek = diff % 7;
			// If division goes without remain then day should be Monday
			if (dayOfWeek == 0)
				System.out.println("The desired day is " + DayNames[dayOfWeek]);
			// If division has remain than we should count day from the end of array with day names
			else
				System.out.println("The desired day is " + DayNames[7-dayOfWeek]);
		}
		// Countdown of difference in days if input date is later than initial
		else {
			for (int y = defYear; y < year; y++){
				if (y % 4 == 0){
					diff += 366;
					System.out.println("Diff="+diff);
				}
				else{
					diff += 365;
					System.out.println("Diff="+diff);
				}	
			}
			for (int m = defMonth; m < month; m++){
				if (m == 2 & (year % 4 == 0)){
					diff += 29;
					System.out.println("Diff="+diff);
				}
				else if (m == 2 & (year % 4 != 0)){
					diff += 28;
					System.out.println("Diff="+diff);
				}
				else if (m == 4 | m == 6 | m == 9 | m ==11){
					diff += 30;
					System.out.println("Diff="+diff);
					}
				else{ 
					diff += 31;
					System.out.println("Diff="+diff);
				}
			}
			int daydiff = day - defDay;
			diff += daydiff;
			System.out.println("Diff="+diff);
			int dayOfWeek = diff % 7;
			System.out.println("The desired day is " + DayNames[dayOfWeek]);
		}
	}
}